package com.itheima.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "myFilter", urlPatterns = "/*")
public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {

        System.out.println("MyFilter...");
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
//
//        // 放行 Knife4j 的相关路径
//        if (request.getRequestURI().contains("/doc.html") || request.getRequestURI().contains("/favicon.ico")) {
//            chain.doFilter(servletRequest, servletResponse);
//            return;
//        }

        //放行
        chain.doFilter(servletRequest, servletResponse);
    }
}
